<?php
$urlData = array(
    'cooker' => 'BCafeBill@addBill',
    'billId' => $billId
);
if (isset($memberPointAccountId)) {
    $urlData['memberPointAccountId'] = $memberPointAccountId;
}
if (isset($mobileField) && $model->$mobileField != NULL) {
    $urlData['mobile'] = $model->$mobileField;
}
if (isset($openidField) && $model->$openidField != NULL) {
    $urlData['openid'] = $model->$openidField;
//    echo $urlData['openid'];
}
if (isset($userNameField) && $model->$userNameField != NULL) {
    $urlData['name'] = $model->$userNameField;
}
if (isset($fixedCardIdField) && $model->$fixedCardIdField != NULL) {
    $urlData['fixedCardId'] = $model->$fixedCardIdField;
}
$url = $control->getAjaxLinkUrl('addBill', NULL, $urlData);
$updateId = $control->getAjaxContainerId();
?>

<?php
$form = $this->beginWidget('CActiveForm', array(
    "id" => "addBillForm",
    'enableAjaxValidation' => FALSE,
    'htmlOptions' => array('enctype' => 'multipart/form-data'),
        ));
?>
<script type="text/javascript">
// this script for collecting the form data and pass to the controller action and doing the on success validations
    function saveBillRequest() {
        var formData = new FormData($("#addBillForm")[0]);
        $.ajax({
            url: '<?php echo $url; ?>',
            type: 'POST',
            data: formData,
            //datatype: 'json',
            // async: false,
            beforeSend: function() {
                $("#ajax-loaderdiv").show();
            },
            success: function(html) {
                // on success do some validation or refresh the content div to display the uploaded images 
                jQuery("#<?php echo $updateId; ?>").html(html);
            },
            complete: function() {
                $("#ajax-loaderdiv").hide();
            },
            error: function(data) {
                alert("There may a error on uploading. Try again later");
            },
            cache: false,
            contentType: false,
            processData: false
        });

        return false;
    }
</script>
<legend><h4><?php
        echo $control->getAjaxLink(array('name' => '功能列表', 'id' => 'showEventList'), array(
            'cooker' => 'BAEvent@showEventList'
        ));
        ?>\
        <?php
        echo $control->getAjaxLink(array('name' => '买单类型', 'id' => 'ShowBillTypeList'), array(
            'cooker' => 'BCafeBill@showBillTypeList'
        ));
        ?>\
        <?php
        echo $control->getAjaxLink(array('name' => '管理买单', 'id' => 'showManageBill'), array(
            'cooker' => 'BCafeBill@showManageBill'
        ));
        ?>\
        <?php
        /*
          $mBillCooker = new BCafeBillCooker();
          $billTypeAlias = $mBillCooker->getCurrentBillType()->getValue();
          echo $control->getAjaxLink(array('name' => $billTypeAlias, 'id' => 'showBillList'), array(
          'cooker' => 'BCafeBill@showBillList'
          ));
         * 
         */
        ?>
        <?php
        if ($billId == NULL || $billId == 0) {
            $title = '客户买单';
        }
        if (is_numeric($billId) && $billId > 0)
            $title = '修改买单';
        echo $title;
        ?>
    </h4></legend>
<div class="tabbable tabs-right" style="margin-top: 15px;"> <!-- Only required for left/right tabs -->
    <ul class="nav nav-tabs" style="margin-bottom: 15px">
        <li class="active"><a href="#tab1" data-toggle="tab"><?php echo '基本信息'; ?></a></li>
        <li class=""><a href="#tab2" data-toggle="tab"><?php echo '代金券'; ?></a></li>
        <li class=""><a href="#tab3" data-toggle="tab"><?php echo '其他属性'; ?></a></li>    
    </ul>
    <div class="tab-content">
        <div class="tab-pane active" id="tab1" style="min-height: 180px">                
            <?php
            //增加默认字段
            ?>
            <table class="table table-hover">
                <colgroup>
                    <col class="span1">
                    <col class="span7">
                </colgroup>
                <thead>
                    <tr>
                        <th><?php echo '属性'; ?></th>
                        <th><?php echo '内容'; ?></th>
                    </tr>
                </thead>
                <tbody>
                    <tr><td> <?php echo '消费金额（元）'; ?> </td>
                        <td>
                            <?php
                            echo $form->textField($model, $amountField, array('placeholder' => '买单金额' . '...', 'required' => true));
                            ?>
                        </td>
                    </tr>
                    <tr><td> <?php echo '桌号'; ?> </td>
                        <td>
                            <?php
                            echo $form->textField($model, $seatField, array('placeholder' => '桌号' . '...', 'required' => true));
                            ?>
                        </td>
                    </tr>
                    <?php if (isset($fixedCardIdField) && $model->$fixedCardIdField != NULL) { ?>
                        <tr><td> <?php echo '实体卡号'; ?> </td>
                            <td>
                                <?php
                                echo $form->textField($model, $fixedCardIdField, array('placeholder' => '实体卡号' . '...', 'required' => true, 'disabled' => TRUE));
                                ?>
                            </td>
                        </tr>
                    <?php } ?>
                    <?php if (isset($mobileField) && $model->$mobileField != NULL) { ?>
                        <tr><td> <?php echo '用户手机'; ?> </td>
                            <td>
                                <?php
                                echo $form->textField($model, $mobileField, array('placeholder' => '手机号' . '...', 'required' => true, 'disabled' => TRUE));
                                ?>
                            </td>
                        </tr>   
                    <?php } ?>
                    <?php if (isset($memberPointAccountId) && $memberPointAccountId != NULL && $model->$userNameField != NULL) { ?>
                        <tr><td> <?php echo '客户称谓'; ?> </td>
                            <td>
                                <?php
                                echo $form->textField($model, $userNameField, array('placeholder' => '客户称谓' . '...', 'disabled' => TRUE));
                                ?>
                            </td>
                        </tr>   
                    <?php } ?>
                    <?php if (isset($memberPointField) && $model->$memberPointField != NULL) { ?>
                        <tr><td> <?php echo '客户积分'; ?> </td>
                            <td>
                                <?php
                                echo $form->textField($model, $memberPointField, array('placeholder' => '客户积分' . '...', 'required' => true, 'disabled' => TRUE));
                                ?>
                            </td>
                        </tr>   
                    <?php } ?>
                    <?php if (isset($memberPointAccountId) && $memberPointAccountId != NULL && isset($deductedMemberPointField)) { ?>
                        <tr><td> <?php echo '兑换积分'; ?> </td>
                            <td>
                                <?php
                                echo $form->textField($model, $deductedMemberPointField, array('placeholder' => '兑换积分' . '...', 'required' => true));
                                ?>
                            </td>
                        </tr>   
                    <?php } ?>
                    <tr>
                        <td> <?php echo '说明'; ?>  </td>                    
                        <td>
                            <?php
                            echo $form->textArea($model, $descriptionField, array('placeholder' => '说明' . '...'));
                            ?>
                    </tr>
                    <?php if ($model->$billTimeField != NULL) { ?>
                        <tr><td> <?php echo '买单时间'; ?> </td>
                            <td>
                                <?php
                                echo $form->textField($model, $billTimeField, array('placeholder' => '买单时间' . '...', 'required' => true, 'disabled' => 'true'));
                                ?>
                            </td>
                        </tr>
                    <?php } ?>
                </tbody>
            </table>
        </div>
        <div class="tab-pane" id="tab2" style="min-height: 180px">                
            <?php
            $billCooker = new BAWeBillCooker();
            $control2 = new BUIEventControl('billVoucher');
            $viewData = array();
            $viewData['billId'] = $billId;
            if ($model->$mobileField != NULL) {
                $mobile = $model->$mobileField;
                $viewData['mobile'] = $mobile;
            }
            $billCooker->showBillVoucherList($control2, $viewData);
            ?>
        </div>
        <div class="tab-pane" id="tab3" style="min-height: 180px">                
            <?php
            if (isset($bill) && $bill != NULL) {
                $control1 = new BUIAttribute('showBillAttribute');

                $control1->prepareAttributeView('billAttribute', $bill, 'add_bill');
                $control1->render();
            }
            ?>  
        </div>
    </div>
</div>
<?php
$this->endWidget();
?>
<div class="row-fluid">
    <button class="btn" onclick="javascript:saveBillRequest()"><?php echo '保存' ?></button>
</div>